package com.sprint.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sprint.controller.utils.R;
import com.sprint.domain.Book;
import com.sprint.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import java.util.List;

//@RestController
//@RequestMapping("/books")
public class BookController {

    @Autowired
    private IBookService bookService;

    @GetMapping
    public List<Book> getAll()
    {
        R r = new R();
        r.setFlag(true);
        r.setData(bookService.list());
        return bookService.list();
    }

    @PostMapping
    public Boolean save(@RequestBody Book book)
    {
        return bookService.save(book);
    }

    @PutMapping
    public Boolean updatebyId(@RequestBody Book book)
    {
        return bookService.updateById(book);
    }

    @DeleteMapping("{id}")
    public Boolean updatebyId(@PathVariable Integer id)
    {
        return bookService.removeById(id);
    }

    @GetMapping("{currentPage}/{pageSize}")
    public IPage<Book> getPage(@PathVariable Integer currentPage, @PathVariable Integer pageSize)
    {
        return bookService.getPage2(currentPage,pageSize);
    }

}

